package com.example.ireader;

import android.app.Activity;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

/**
 * Created by Administrator on 2017/12/6.
 */

public class Category_First_Left_Fragment_Adapter extends RecyclerView.Adapter<Category_First_Left_Fragment_Adapter.ViewHolder> {

    private List<Category_First_Left_Fragment_Item> mItemList;
    private Activity activity = null;
    private int POS;

    static class ViewHolder extends RecyclerView.ViewHolder {
        View Category_First_Left_Fragment_View;
        TextView Item_Name;

        public ViewHolder (View view) {
            super(view);
            Category_First_Left_Fragment_View = view;
            Item_Name = (TextView) view.findViewById(R.id.category_first_left_fragment_item_name);
        }
    }

    public Category_First_Left_Fragment_Adapter(List<Category_First_Left_Fragment_Item> itemList, Activity activity,int POS){
        mItemList = itemList;
        this.activity =activity;
        this.POS = POS;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.category_first_left_fragment_item,parent,false);
        final ViewHolder holder = new ViewHolder(view);
        holder.Category_First_Left_Fragment_View.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                int position = holder.getAdapterPosition();
                Category_First_Left_Fragment_Item category_first_left_fragment_item = mItemList.get(position);
                //点击事件
                POS=position;
                CategoryActivity categoryActivity = (CategoryActivity)activity;
                switch (category_first_left_fragment_item.get_Category_First_Left_Fragment_Item_name()){
                    case "男频":
                        POS=0;
                        categoryActivity.getPOS(POS);
                        categoryActivity.replaceRightFragment("男频");
                        categoryActivity.replaceLeftFragment();
                        break;
                    case "女频":
                        POS=1;
                        categoryActivity.getPOS(POS);
                        categoryActivity.replaceRightFragment("女频");
                        categoryActivity.replaceLeftFragment();
                        break;
                    case "杂志":
                        POS=2;
                        categoryActivity.getPOS(POS);
                        categoryActivity.replaceRightFragment("杂志");
                        categoryActivity.replaceLeftFragment();
                        break;
                    case "漫画":
                        POS=3;
                        categoryActivity.getPOS(POS);
                        categoryActivity.replaceRightFragment("漫画");
                        categoryActivity.replaceLeftFragment();
                        break;
                    case "出版":
                        POS=4;
                        categoryActivity.getPOS(POS);
                        categoryActivity.replaceRightFragment("出版");
                        categoryActivity.replaceLeftFragment();
                        break;
                    default:
                        break;
                }
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Category_First_Left_Fragment_Item item = mItemList.get(position);
        holder.Item_Name.setText(item.get_Category_First_Left_Fragment_Item_name());

        if (position == POS){
            holder.itemView.setBackgroundColor(Color.parseColor("#fdfdfe"));
        }
        else {
            holder.itemView.setBackgroundColor(Color.parseColor("#EC4A48"));
        }
    }

    @Override
    public int getItemCount() {
        return mItemList.size();
    }
}
